﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using CDB.LinqModel.Data;
using CDB.LinqModel;
using CDB.LinqData;
using System.Web.UI.WebControls;
using System.Collections.Generic;

public partial class Builders : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    Builder builder;
    City city;
    List<Builder> builders = new List<Builder>();
    List<City> cities = new List<City>();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //bindCities();
        }
    }
    //private void bindCities()
    //{
    //    city = new City(_dataObject);
    //    cities = city.GetCitiesByBuilders();

    //    if (cities.Count > 0)
    //    {
    //        ddlCity.DataSource = cities;
    //        ddlCity.DataTextField = "Name";
    //        ddlCity.DataValueField = "Id";
    //        ddlCity.DataBind();
    //        ddlCity.Items.Insert(0, "Select City");
    //    }
    //}
    protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindBuilderGrid();
    }
    private void bindBuilderGrid()
    {
        builder = new Builder(_dataObject);
        builders = builder.GetBuildersByLocation(ddlCity.SelectedValue);
        if (builders.Count > 0)
        {
            dListBuilders.DataSource = builders;
            dListBuilders.DataBind();
        }
        else
        {
            dListBuilders.DataSource = null;
            dListBuilders.DataBind();
        }
    }
    protected void dListBuilders_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HtmlGenericControl spDateCreated = (HtmlGenericControl)e.Item.FindControl("spDateCreated");
            Label spanDate = (Label)e.Item.FindControl("spanDate");

            if (!string.IsNullOrEmpty(spanDate.Text))
            {
                spDateCreated.InnerHtml = "<small>" +
                                          ((CDB.LinqModel.CDBGeneral.Month)Convert.ToDateTime(spanDate.Text).Month).
                                              ToString() + "</small>";
                spDateCreated.InnerHtml += "<div>" +
                                           (Convert.ToDateTime(spanDate.Text).Day).
                                               ToString() + "</div>";
            }
        }
    }
}